//
//  SideViewController.m
//  news_ios_app
//
//  Created by apple on 16/3/16.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "SideViewController.h"



@implementation customScrollView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.bounces = NO;
        self.pagingEnabled = YES;
        self.showsVerticalScrollIndicator = NO;
        self.showsHorizontalScrollIndicator = NO;
    }
    return self;
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    [super gestureRecognizerShouldBegin:gestureRecognizer];
    
    
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        if ([gestureRecognizer locationInView:self].x > 50 + BOUNDWIDTH * swipProportion) {
            return NO;
        }
    }
    return YES;
}

@end

typedef NS_ENUM(NSInteger, MainViewStatus){
    MainViewStatusHome=1,
    MainViewStatusSide
};

@interface SideViewController ()<UIScrollViewDelegate>
@property (strong,nonatomic) UIView *testView;
@property (strong,nonatomic) HomeViewController *homeVC;
@property (assign,nonatomic) MainViewStatus mainViewStatus;
@property (strong,nonatomic) customScrollView *scrollView;
@property (strong,nonatomic) SideMenuViewController *menuVC;
@end

@implementation SideViewController

-(instancetype)init
{
    if (self = [super init]) {
        self.view.backgroundColor = [UIColor whiteColor];
        _mainViewStatus = MainViewStatusHome;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    _menuVC = [[SideMenuViewController alloc]init];
    _menuVC.view.frame = CGRectMake(-BOUNDWIDTH * swipProportion * 0.5, 0, BOUNDWIDTH, BOUNDHEIGHT);
    [self.view addSubview:_menuVC.view];

    
    _scrollView = [[customScrollView alloc]initWithFrame:CGRectMake(0, 0, BOUNDWIDTH, BOUNDHEIGHT)];
    _scrollView.contentSize = CGSizeMake(BOUNDWIDTH * 1.8, BOUNDHEIGHT);
    [_scrollView setContentOffset:CGPointMake(BOUNDWIDTH*0.8,0) animated:NO];
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    
    
    _homeVC = [[HomeViewController alloc]init];
    _homeVC.view.frame = CGRectMake(BOUNDWIDTH * 0.8, 0, BOUNDWIDTH, BOUNDHEIGHT);

    [_scrollView addSubview:_homeVC.view];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat x = scrollView.contentOffset.x;
    _menuVC.view.frame = CGRectMake(-(x/2), 0, BOUNDWIDTH * swipProportion, BOUNDHEIGHT);
}

-(void)showHome
{
     [_scrollView setContentOffset:CGPointMake(BOUNDWIDTH*0.8,0) animated:YES];
}

-(void)showMenu
{
     [_scrollView setContentOffset:CGPointMake(0,0) animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
